package org.gpp.proj1.logic.metadata;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import org.gpp.proj1.robot.part.Part;


/**
 * @author Paolo Victor, paolovictor@gmail.com
 */
public class PartEntry implements Serializable {

	private static final long serialVersionUID = 1613690477398699119L;

	private String file;
	
	private String name;

	private int energy;

	private int attack;

	private int defense;

	private int speed;

	private int price;

	private List<String> actions;
	
	public PartEntry( Part part, String partfile ) {
		this.name = part.getName();
		
		this.energy = Integer.parseInt( part.getAttribute( Part.ENERGY ) );
		this.attack = Integer.parseInt( part.getAttribute( Part.ATTACK ) );
		this.defense = Integer.parseInt( part.getAttribute( Part.DEFENSE ) );
		this.speed = Integer.parseInt( part.getAttribute( Part.SPEED ) );
		
		this.price = part.getPrice();
		
		this.file = partfile;
		
		this.actions = new LinkedList<String>( part.getActions() );
	}
	
	public String getPartfile() {
		return file;
	}
	
	public String toString() {
		return name + ":" + file;
	}
	
	public String getPartDescription() {
		String description = "Price: " + price + "\u00a2\n\n";
		description += "Energy: " + energy + "\n";
		description += "Attack: " + attack + "\n";
		description += "Defense: " + defense + "\n";
		
		if( speed > 0 ) { 
			description += "Speed: " + speed + "\n";
		}
		
		description += "\n";

		if( actions.size() > 0 ) {
			description += "Actions:\n";
			for( String action : actions ) {
				description += "  " + action + "\n";
			}
		}
		
		return description;
	}
	
	public boolean equals( Object o ) {
		if( ! ( o instanceof PartEntry ) ) { 
			return false;
		}
		
		PartEntry other = (PartEntry) o;
		
		return other.toString().equals( this.toString() );
	}
	
	public int hashcode() {
		return this.name.hashCode();
	}

	public String getFile() {
		return file;
	}

	public String getName() {
		return name;
	}

	public int getPrice() {
		return price;
	}
}
